package com.sw.haruka.model;

import android.content.Context;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.sw.haruka.helper.utils.Configuration;
import com.sw.haruka.helper.utils.UUtils;

public abstract class BaseActivity extends AppCompatActivity {

    protected abstract int layoutId();
    protected abstract void initView();
    protected abstract void loadData(boolean isRefresh);
    protected void initEvent() {}
    protected Context mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        UUtils.baseStatus(this);        // 设置状态栏为白底黑字
        setContentView(layoutId());
        mContext = this;
        initView();
        initEvent();
        loadData(true);
    }

    @Override
    protected void onResume() {
        super.onResume();
        closeKeyboard();
    }

    /**
     * 自动关闭软键盘
     */
    public void closeKeyboard() {
        InputMethodManager imm =  (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        if(imm != null) {
            imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    @Override
    public void setRequestedOrientation(int requestedOrientation) {
        super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}
